home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / devices and hardware / disks / iso9660 / dialogutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.5 KB  |  98 lines

  1. /*
  2.     File:        DialogUtils.c
  3.     
  4.     Description:
  5.  
  6.     Author:        ME
  7.  
  8.     Copyright:     Copyright: © 1999 by Apple Computer, Inc.
  9.                 all rights reserved.
  10.     
  11.     Disclaimer:    You may incorporate this sample code into your applications without
  12.                 restriction, though the sample code has been provided "AS IS" and the
  13.                 responsibility for its operation is 100% yours.  However, what you are
  14.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  15.                 after having made changes. If you're going to re-distribute the source,
  16.                 we require that you make it clear in the source that the code was
  17.                 descended from Apple Sample Code, but that you've made changes.
  18.     
  19.     Change History (most recent first):
  20.                 6/24/99    Updated for Metrowerks Codewarror Pro 2.1(KG)
  21.  
  22. */
  23. /* DialogUtils.c */
  24.  
  25. #include <QuickDraw.h>
  26. #include <Menus.h>
  27. #include <Resources.h>
  28. #include <StandardFile.h>
  29. #ifndef topLeft
  30. #define topLeft(r)    (((Point *)&(r))[0])
  31. #endif
  32. #ifndef botRight
  33. #define botRight(r)    (((Point *)&(r))[1])
  34. #endif
  35. #include "DialogUtils.h"
  36.  
  37. static void DU_CenterRect(Rect *rect_p);
  38. static Point DU_Where(short rsrcId);
  39. static short DU_Center(ResType type, short rsrcId);
  40.  
  41. static void DU_CenterRect(Rect* rect_p){
  42. /*
  43.  * Aligns *rect_p wrt screenBits.bounds - LR centered & in upper 1/3
  44.  */
  45.  
  46.     /* exactly centered */
  47.     OffsetRect(rect_p,
  48.             (qd.screenBits.bounds.right + qd.screenBits.bounds.left)/2 -
  49.                 (rect_p->right + rect_p->left)/2
  50.         ,
  51.             (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)/2 -
  52.                 (rect_p->top + rect_p->bottom)/2
  53.         );
  54.     
  55.     /* up a bit */
  56.     OffsetRect(rect_p,0, 
  57.         GetMBarHeight() - 2*(rect_p->top - qd.screenBits.bounds.top)/3);
  58. }
  59.  
  60. static Point DU_Where(short rsrcId){
  61. /*
  62.  * Returns centering point for the topLeft corner of a dialog.
  63.  */
  64.     Handle  h = GetResource('DLOG',rsrcId);
  65.     Rect    r = {0,0,0,0};
  66.     if(h){
  67.         r = *((Rect*)(*h));
  68.         DU_CenterRect(&r);
  69.         ReleaseResource(h);
  70.     }
  71.     return topLeft(r);
  72. }
  73.  
  74. Point DU_StdPutWhere(void){
  75.     return DU_Where(putDlgID);
  76. }
  77.  
  78. Point DU_StdGetWhere(void){
  79.     return DU_Where(getDlgID);
  80. }
  81.  
  82. static short DU_Center(ResType type, short rsrcId){
  83. /*
  84.  * Reads in an 'ALRT' or 'DLOG' rsrc template & centers it's display Rect.
  85.  */
  86.     Handle  h = GetResource(type,rsrcId);
  87.     if(h) DU_CenterRect((Rect*)(*h));
  88.     return rsrcId;
  89. }
  90.  
  91. short DU_CenterALRT(short rsrcId){
  92.     return DU_Center('ALRT',rsrcId);
  93. }
  94.  
  95. short DU_CenterDLOG(short rsrcId){
  96.     return DU_Center('DLOG',rsrcId);
  97. }
  98.